#ifndef __SN32F280_FLASH_H
#define __SN32F280_FLASH_H

/*_____ I N C L U D E S ____________________________________________________*/
#include "SN32F280.h"
#include "SN32F200_Def.h"


/*_____ D E F I N I T I O N S ______________________________________________*/
//FLASH HW
#define	FLASH_PAGE_SIZE							1024
#define	FLASH_F240_MAX_ROM_SIZE			0xFFFF
#define	FLASH_F230_MAX_ROM_SIZE			0x7FFF
#define	FLASH_F220_MAX_ROM_SIZE			0x3FFF


// Flash Control Register definitions
#define FLASH_PG										0x00000001
#define FLASH_PER										0x00000002
#define FLASH_START									0x00000040

// Flash Status Register definitions
#define FLASH_BUSY									0x00000001
#define FLASH_PGERR									0x00000004


/*_____ M A C R O S ________________________________________________________*/

//Flash Low Power Mode
#define	__FLASH_LPM_DISABLE					SN_FLASH->LPCTRL = 0x5AFA0000
#define	__FLASH_LPM_SLOW_MODE				SN_FLASH->LPCTRL = 0x5AFA0002

#define	FLASH_PROGRAM_ONE_WORD 1	//** 1word
#define	FLASH_PROGRAM_ONE_PAGE 16 //** 16words

#define FLASH_ERR									0x00000004
//Flash Status
#define	__FLASH_CLEAR_ERROR_STATUS	SN_FLASH->STATUS &= ~FLASH_PGERR
#define	FLASH_WAIT_FOR_DONE		while (SN_FLASH->STATUS & FLASH_BUSY) {__nop();}

/*_____ D E C L A R A T I O N S ____________________________________________*/
extern	uint8_t wFLASH_PGRAM[1024];

void FLASH_EraseSector (uint32_t);
uint32_t FLASH_ProgramPage_Byte(volatile uint32_t adr, volatile uint32_t sz, uint8_t *pBuf);
int FLASH_ProgramPage (uint32_t adr, uint32_t sz, uint32_t* buf);
uint32_t FLASH_ProgramPage_Word(volatile uint32_t adr, volatile uint32_t sz, uint32_t *pBuf);

#endif	/* __SN32F280_FLASH_H */
